22.03.02 - Thinking Recursively
What are recursive functions?
A recursive function is a function defined in terms of itself, self referential
Why are they useful?
Many, if not most functions have a simple recursive definition. fundamentally recursion is the only way of doing any kind of loop
Why are they difficult at first?
Different way of thinking. Alternative way to looping.
Way to write a recursive function
- Name the function
- Write down its type
- Enumerate the cases (skeleton)
- Define the simple cases (Base Case (Non recursive Case))
- List the 'ingredients'
- Define the other case
- Think about the result